Component({
  /**
   * 组件的属性列表
   */
  properties: {
    title: {
      type: String,
      value: "广师大科教"
    },
    iconUrl: {
      type: String,
      value: "/image/test.png"
    },
    createTime: {
      type: String,
      value: "2024-08-03  12:55"
    },
    fileUrl: {
      type: String,
      value: ""
    },
    status: {
      type: Number,
      value: 0
    },
    deptName: {
      type: String,
      value: "无"
    }

  },

  /**
   * 组件的初始数据
   */
  data: {

  },

  /**
   * 组件的方法列表
   */
  methods: {
    //录取查询
    handleQuery(e) {
      console.log(this.properties.status)
      const that = this
      wx.navigateTo({
        url: "/pages/queryResult/queryResult?status=" + that.properties.status + "&deptName=" + that.properties.deptName
      })
    },
    //查看附件  
    openFile(e) {
      console.log(this.properties.fileUrl)
      wx.showLoading({
        title: '打开文件中',
        mask: true
      })
      const that = this
      const fileName = this.getFilePathName(this.properties.fileUrl);
      console.log(fileName)
      wx.downloadFile({
        url: "https://" + that.properties.fileUrl,
        filePath: wx.env.USER_DATA_PATH + '/' + fileName,
        header: {
          'token': wx.getStorageSync('token')
        },
        success: function (res) {
          wx.openDocument({
            filePath: wx.env.USER_DATA_PATH + '/' + fileName,
            showMenu: true,
            success: function (params) {
              console.log("打开文件成功")
              wx.hideLoading()
            },
            fail: function (params) {
              wx.showToast({
                title: '打开文件失败',
              })
              wx.hideLoading()
            }

          })
          wx.hideLoading()
        },
        fail: function (err) {
          wx.showToast({
            title: '获取文件失败',
          })
          console.log(err)
          wx.hideLoading()
        },

      })
    },
    //获取URL中的文件名
    getFilePathName(path) {
      let pos1 = path.lastIndexOf('/');
      let pos2 = path.lastIndexOf('\\');
      let position = Math.max(pos1, pos2);
      if (position < 0)
        return path;
      else
        return path.substring(position + 1);
    }
  },
})